package top.loveyumin1314.music.logic;

import top.loveyumin1314.music.bean.UserActionBean;
import top.loveyumin1314.music.code.ActionCode;
import top.loveyumin1314.music.lottery.LotteryService;
import top.loveyumin1314.music.lottery.LotteryServiceImpl;

import java.io.IOException;


public class LogicDispatcher implements IDispatcher {

    private static LogicDispatcher INSTANCE;

    public static LogicDispatcher instance() {
        if (INSTANCE == null) {
            synchronized (LogicDispatcher.class) {
                if (INSTANCE == null) {
                    INSTANCE = new LogicDispatcher();
                }
            }
        }
        return INSTANCE;
    }

    private LogicDispatcher() {
    }

    private static final LotteryService lotteryService = new LotteryServiceImpl();


    @Override
    public Object handleMessage(UserActionBean userActionBean) throws IOException {
        Integer actionId = userActionBean.getActionId();

        if (actionId.equals(ActionCode.ADD_LOTTORY_MINE.actionId)) {
            return lotteryService.addLotteryUser(userActionBean);
        } else if (actionId.equals(ActionCode.ADD_LOTTORY.actionId)) {
            return lotteryService.addLotteryUser(userActionBean);
        } else if (actionId.equals(ActionCode.REMOVE_LOTTORY_MINE.actionId)) {
            return lotteryService.removeLotteryUser(userActionBean);
        } else if (actionId.equals(ActionCode.REMOVE_LOTTORY.actionId)) {
            return lotteryService.removeLotteryUser(userActionBean);
        } else if (actionId.equals(ActionCode.GET_LOTTORY_LIST.actionId)) {
            return lotteryService.getLotteryList(userActionBean);
        } else if (actionId.equals(ActionCode.START_LOTTORY.actionId)) {
            return lotteryService.startLottory(userActionBean);
        } else if (actionId.equals(ActionCode.STOP_LOTTORY.actionId)) {
            return lotteryService.stopLottory(userActionBean);
        }
        return userActionBean;
    }
}
